/*=====================================================
Critical Links
Auto Configuration Server

Authors:
	Rui Eduardo Gouveia Gil - r-gil@critical-links.com

Date: 2010
Version 0.1
=======================================================*/
#include "database/DataBase.h"
#include "data/Log.h"

namespace acs
{

Log::Log()
{

}

Log::Log(LogLevel level, int deviceID, std::string ip, std::string name, std::string license, std::string release, std::string customer, std::string command, std::string result, std::string message)
{
	this->id = 0;
	this->level = level;
	time(&this->date);
	this->deviceID = deviceID;
	this->ip = ip;
	this->name = name;
	this->license = license;
	this->release = release;
	this->customer = customer;
	this->command = command;
	this->result = result;
	this->message = message;
}

Log::~Log()
{

}

void Log::setID(const int id)
{
	this->id = id;
}

int Log::getID() const
{
	return this->id;
}

void Log::setDate(const time_t date)
{
	this->date = date;
}

time_t Log::getDate() const
{
	return this->date;
}

void Log::setDeviceID(const int deviceID)
{
	this->deviceID = deviceID;
}

int Log::getDeviceID() const
{
	return this->deviceID;
}

void Log::setLevel(const LogLevel level)
{
	this->level = level;
}

LogLevel Log::getLevel() const
{
	return this->level;
}

std::string Log::getLevelStr() const
{
	switch(this->level)
	{
		case ACS_LL_DEBUG:
		{
			return "Trace";
		}break;

		case ACS_LL_NOTICE:
		{
			return "Notice";
		}break;

		case ACS_LL_WARNING:
		{
			return "Warning";
		}break;

		case ACS_LL_ERROR:
		{
			return "Error";
		}break;
	}

	return "none";
}

std::string Log::getLevelIcon() const
{
	switch(this->level)
	{
		case ACS_LL_DEBUG:
		{
			return "<img style=\"padding-left: 2px; padding-top: 5px; height: 16px;\" src=\"images/large-orange-sphere.ico\" alt=\"online\" onmouseover=\"javascript:showTooltip(this,event,'pending tasks');\" onmouseout=\"javascript:hideTooltip();\"/>";
		}break;

		case ACS_LL_NOTICE:
		{
			return "<img style=\"padding-left: 2px; padding-top: 5px; height: 16px;\" src=\"images/large-orange-sphere.ico\" alt=\"online\" onmouseover=\"javascript:showTooltip(this,event,'pending tasks');\" onmouseout=\"javascript:hideTooltip();\"/>";
		}break;

		case ACS_LL_WARNING:
		{
			return "<img style=\"padding-left: 2px; padding-top: 5px; height: 16px;\" src=\"images/large-orange-sphere.ico\" alt=\"online\" onmouseover=\"javascript:showTooltip(this,event,'pending tasks');\" onmouseout=\"javascript:hideTooltip();\"/>";
		}break;

		case ACS_LL_ERROR:
		{
			return "<img style=\"padding-left: 2px; padding-top: 5px; height: 16px;\" src=\"images/large-orange-sphere.ico\" alt=\"online\" onmouseover=\"javascript:showTooltip(this,event,'pending tasks');\" onmouseout=\"javascript:hideTooltip();\"/>";
		}break;
	}

	return "none";
}

void Log::setIp(const std::string& ip)
{
	this->ip=ip;
}

std::string Log::getIp() const
{
	return this->ip;
}

void Log::setName(const std::string& name)
{
	this->name = name;
}

std::string Log::getName() const
{
	return this->name;
}

void Log::setLicense(const std::string& license)
{
	this->license = license;
}

std::string Log::getLicense() const
{
	return this->license;
}

void Log::setRelease(const std::string& release)
{
	this->release= release;
}

std::string Log::getRelease() const
{
	return this->release;
}

void Log::setCustomer(const std::string& customer)
{
	this->customer = customer;
}

std::string Log::getCustomer() const
{
	return this->customer;
}

void Log::setCommand(const std::string& command)
{
	this->command = command;
}

std::string Log::getCommand() const
{
	return this->command;
}

void Log::setResult(const std::string& result)
{
	this->result = result;
}

std::string Log::getResult() const
{
	return this->result;
}

void Log::setMessage(const std::string& message)
{
	this->message = message;
}

std::string Log::getMessage() const
{
	return this->message;
}

std::string Log::toXML() const
{
	std::stringstream stream;

	stream << "<Log>";
	stream << "<ID>" <<  this->id << "</ID>";
	stream << "<Date>" <<  this->date << "</Date>";
	stream << "<DateStr>" <<  rgcpp::ToString(this->date,"%Y-%m-%d %X") << "</DateStr>";
	stream << "<DeviceID>" <<  this->deviceID << "</DeviceID>";
	stream << "<DeviceName>" <<  DataBase::getInstance()->getDevice(this->deviceID).getName() << "</DeviceName>";
	stream << "<LogLevel>" <<  this->level << "</LogLevel>";
	stream << "<LogLevelStr>" <<  this->getLevelStr() << "</LogLevelStr>";
	stream << "<LogLevelIcon>" <<  this->getLevelIcon() << "</LogLevelIcon>";
	stream << "<Ip>" <<  this->ip << "</Ip>";
	stream << "<Name>" <<  this->name << "</Name>";
	stream << "<License>" <<  this->license << "</License>";
	stream << "<Release>" <<  this->release << "</Release>";
	stream << "<Customer>" <<  this->customer << "</Customer>";
	stream << "<Command>" <<  this->command << "</Command>";
	stream << "<Result>" <<  this->result << "</Result>";
	stream << "<Message>" <<  this->message << "</Message>";
	stream << "</Log>";

	return stream.str();
}

}
